package com.manage.server.controller.admin;

import com.manage.dto.PermissionDTO;
import com.manage.dto.add.PermissionAddDTO;
import com.manage.dto.update.PermissionUpdateDTO;
import com.manage.result.PageResult;
import com.manage.server.service.PermissionService;
import com.manage.vo.PermissionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.manage.result.Result;

@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    @PostMapping
    public Result add(@RequestBody PermissionAddDTO permissionAddDTO) {
        permissionService.save(permissionAddDTO);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        permissionService.removeById(id);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody PermissionUpdateDTO permissionUpdateDTO) {
        permissionService.updateById(permissionUpdateDTO);
        return Result.success();
    }

    /**
     * 多项分类分页查询
     * @param permissionDTO
     * @return
     */
    @PostMapping("/page")
    public PageResult<PermissionVO> findPermission(@RequestBody PermissionDTO permissionDTO) {
        return permissionService.findPermissionByPage(permissionDTO);
    }
}